package com.example.lib_common;

import android.app.Application;

import com.alibaba.android.arouter.BuildConfig;
import com.alibaba.android.arouter.facade.Postcard;
import com.alibaba.android.arouter.launcher.ARouter;

import java.util.HashMap;
import java.util.Map;

/**
 * @author 浪
 * date   2023/7/10
 * desc
 */
public class ARouterUtils {


    public static void init(Application application) {
        // 这两行必须写在init之前，否则这些配置在init过程中将无效
        if (BuildConfig.DEBUG) {
            // 打印日志
            ARouter.openLog();
            // 开启调试模式(如果在InstantRun模式下运行，必须开启调试模式！线上版本需要关闭,否则有安全风险)
            ARouter.openDebug();
        }
        ARouter.init(application);
    }



    public static void navigation(String path) {
        ARouter.getInstance().build(path)
                .navigation();
    }

    public static void navigation(String path, HashMap<String, Object> map) {
        Postcard postcard = ARouter.getInstance().build(path);
        for (Map.Entry<String, Object> entry : map.entrySet()) {
            postcard.withObject(entry.getKey(), entry.getValue());
        }
        postcard.navigation();
    }

    public static Postcard build(String path) {
        return ARouter.getInstance().build(path);
    }
}
